package com.shizhanzhe.zxbapp.widget;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;


import com.shizhanzhe.zxbapp.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by YJ on 2018/11/6.
 */
public class ShareWxPopupWindow extends PopupWindow {
    private View contextView;
    private Activity mContext;
    private ShareWxListener mWxListener;
    @BindView(R.id.tv_shuoming)
    TextView tv;
    @BindView(R.id.xz)
    Button xz;
    public void setWxListener(ShareWxListener wxListener) {
        mWxListener = wxListener;
    }

    public ShareWxPopupWindow(Activity context) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        contextView = inflater.inflate(R.layout.popup_share_wx, null);
        mContext = context;
        this.setContentView(contextView);
        ButterKnife.bind(this, contextView);

        this.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
        this.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        this.update();
        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(30000000);
        // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ，设置其他控件变化等操作
        this.setBackgroundDrawable(dw);
        // mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
        // 设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.my_dialog);
    }

    @OnClick({R.id.wx, R.id.pyq, R.id.xz})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.wx:
                mWxListener.shareFriend();
                break;
            case R.id.pyq:
                mWxListener.shareCircle();
                break;
            case R.id.xz:
                mWxListener.shareSave();
                break;
            default:
        }
    }
    public interface ShareWxListener{
        void shareFriend();
        void shareCircle();
        void shareSave();
    }

    public void showDown(View view) {
        WindowManager.LayoutParams lp = mContext.getWindow().getAttributes();
        lp.alpha = 0.7f;
        mContext.getWindow().setAttributes(lp);
        this.showAtLocation(view, Gravity.CENTER_HORIZONTAL, 0, 0);
    }
    public void showDown2(View view) {
        WindowManager.LayoutParams lp = mContext.getWindow().getAttributes();
        lp.alpha = 0.7f;
        mContext.getWindow().setAttributes(lp);
        this.showAtLocation(view, Gravity.CENTER_HORIZONTAL, 0, 0);
        xz.setVisibility(View.GONE);
        tv.setVisibility(View.GONE);
    }

    @Override
    public void dismiss() {
        super.dismiss();
        WindowManager.LayoutParams lp = mContext.getWindow().getAttributes();
        lp.alpha = 1f;
        mContext.getWindow().setAttributes(lp);
    }

}
